<template>
	<view class="lookAcceptance">
		<view class="uni-padding-wrap uni-common-mt">
			<button type="primary" :class="wag?'active':''" @click="worker(7)">瓦工验收详情</button>
			<button type="primary" :class="mug?'active':''" @click="worker(8)">木工验收详情</button>
			<button type="primary" :class="sdg?'active':''" @click="worker(9)">水电工验收详情</button>
			<button type="primary" :class="yqg?'active':''" @click="worker(10)">油漆工验收详情</button>
			<view class="content">
				验收时间: {{ acceptanceTime || '未验收' }}
			</view>
			<view class="content">
				验收备注: {{ remark }}
			</view>
		</view>
		<view class="content" v-if="imgList.length>0">
			<image v-for="(item, i) in imgList" :key="i" :src="item" mode="aspectFit"></image>
		</view>
		<view class="wu" v-else>
			暂无信息图片
		</view>
		<view class="uni-padding-wrap uni-common-mt" v-if="acceptanceTime">
			<view class="fromSubmit">
				<view class="from-item">
					<view class="item-title">
						<text class="from-item-title">评价</text>
					</view>
					<textarea class="from-item-textarea" maxlength="240" v-model="formSubmit.reserve" placeholder="请输入评价" />
				</view>
				<button type="warn" class="from-button"v-if="!reserve" @click="submit">提交 /Submit</button>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			acceptanceTime: '',
			wag: false,
			mug: false,
			sdg: false,
			yqg: false,
			imgList: [],
			reserve: '',
			remark: '',
			formSubmit: {
				reserve: ''
			},
		}
	},
	onLoad(options) {
		this._id = options.id
		this._bricklayerId = options.bricklayerId
		this._carpenterId = options.carpenterId
		this._plumberId = options.plumberId
		this._painterId = options.painterId
	},
	mounted() {
		const params = {
			workerAccountId: this._bricklayerId,
			houseInfoId: this._id,
			typeLevel: 7
		}
		this.init(params)
		this.init1(params)
		const params1 = {
			workerAccountId: this._carpenterId,
			houseInfoId: this._id,
			typeLevel: 8
		}
		this.init1(params1)
		const params2 = {
			workerAccountId: this._plumberId,
			houseInfoId: this._id,
			typeLevel: 9
		}
		this.init1(params2)
		const params3 = {
			workerAccountId: this._painterId,
			houseInfoId: this._id,
			typeLevel: 10
		}
		this.init1(params3)
	},
	methods: {
		init(params) {
			this.$api.getAcceptanceList(params)
				.then(res => {
					if (res.success) {
						this.acceptanceTime = ''
						this.remark = ''
						this.imgList = []
						this._acceptanceId = res.rows?.id
						if (res.rows) {
							const imgList = res.rows?.acceptancePhoto
							if (imgList) {
								this.imgList = imgList.split(',')
								this.imgList.pop()
							}
							this.remark = res.rows?.remark
							this.acceptanceTime = res.rows?.acceptanceTime
							this.reserve = res.rows?.reserve
						}
					}
				})
				.catch(err => {
					this.$message.error(err)
				})
		},
		init1(params) {
			this.$api.getAcceptanceList(params)
				.then(res => {
					if (res.success) {
						if (res.rows) {
							const imgList = res.rows?.acceptancePhoto
							if (imgList) {
								if (params.typeLevel === 7) {
									this.wag = true
								} else if (params.typeLevel === 8) {
									this.mug = true
								} else if (params.typeLevel === 9) {
									this.sdg = true
								} else if (params.typeLevel === 10) {
									this.yqg = true
								}
							}
						}
					}
				})
				.catch(err => {
					this.$message.error(err)
				})
		},
		worker(type) {
			this._type = type
			const params = {
				workerAccountId: this.$route.query.bricklayerId,
				houseInfoId: this.$route.query.id,
				typeLevel: type
			}
			if (type === 8) {
				params.workerAccountId = this.$route.query.carpenterId
			} else if (type === 9) {
				params.workerAccountId = this.$route.query.plumberId
			} else if (type === 10) {
				params.workerAccountId = this.$route.query.painterId
			}
			this.init(params)
		},
		submit() {
			let params = {
				id: this._acceptanceId,
				typeLevel: this._type,
				reserve: this.formSubmit.reserve
			}
			this.$api.updateAcceptanceInfo(params)
				.then(res => {
					if (res.success) {
						uni.showToast({
						  icon: 'success',
						  title: '提交成功'
						})
						const params = {
							workerAccountId: this._bricklayerId,
							houseInfoId: this._id,
							typeLevel: 7
						}
						this.init(params)
					}
				}).catch(err => {
					this.$message.error(err)
				})
		}
	}
}
</script>

<style lang="scss" scoped>
.lookAcceptance {
	.active {
		background-color: #00B26A;
	}
	.uni-common-mt {
		button {
			margin-top: 20rpx;
		}
	}
	.content {
		margin-top: 20rpx;
		image {
			margin: 20rpx;
		}
	}
	.wu {
		margin-top: 20rpx;
		margin-left: 30rpx;
	}
	.fromSubmit {
		padding: 40rpx;
		.from-item {
			margin-bottom: 40rpx;
			.item-title {
				margin-bottom: 20rpx;
				.from-item-title {
					font-size: 32rpx;
					font-weight: 500;
					color: #333333;
					margin-right: 20rpx;
				}
			}
			.uni-input {
				background: #f6f6f6;
				border-radius: 4px;
			}
			.from-item-textarea {
				background: #f6f6f6;
				width: 100%;
				border-radius: 4px;
			}
		}
		.from-button {
			background: $uni-color-base;
		}
	}
}
</style>
